package org.zkoss.model.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.zkoss.model.bean.Company;
import org.zkoss.model.bean.Contact;

public class ContactDAO extends HibernateDaoSupport {

	public void saveOrUpdate(Contact contact) {
		getHibernateTemplate().saveOrUpdate(contact);
	}

	public void delete(Contact contact) {
		getHibernateTemplate().delete(contact);
	}

	public Contact find(Class<Contact> clazz, Integer id) {
		Contact contact = super.getHibernateTemplate().get(clazz, id);
		return contact;
	}

	@SuppressWarnings("unchecked")
	public List<Contact> findByCompany(Company company, Class<Contact> clazz) {
		List<Contact> list = super.getHibernateTemplate().find("from " + clazz.getName() + " as c where c.companyId = " + company.getIdcompany());
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<Contact> findAll(Class<Contact> clazz) {
		List<Contact> list = super.getHibernateTemplate().find("from " + clazz.getName());
		return list;
	}

}
